<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="项目名称" prop="projectName">
<!--        <el-input-->
<!--          v-model="queryParams.projectName"-->
<!--          placeholder="请输入项目名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select v-model="queryParams.projectName" placeholder="请选择" clearable>
          <el-option
            v-for="item in opations"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目种类" prop="projectType">
<!--        :0-单人赛，1-双人赛，3-团体赛-->
        <el-select v-model="queryParams.projectType" placeholder="请选择项目种类" clearable>
          <el-option
            v-for="dict in projectTypeList1"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="赛事开始时间" prop="actionTime" style="margin-left: 20px">
        <el-date-picker
          clearable
          v-model="queryParams.actionTime"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small " @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="small " @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:information:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:information:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:information:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:information:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目序号" align="center" prop="id" />
      <el-table-column label="图片" align="center" prop="projectName" width="150px">
        <template slot-scope="scope">
          <div v-if="scope.row.projectName == '1'">
           <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000513420751.jpg">
          </div>
          <div v-if="scope.row.projectName == '2'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000514751936.jpg">
          </div>
          <div v-if="scope.row.projectName == '3'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000516743104.jpg">
          </div>
          <div v-if="scope.row.projectName == '4'">
            <img src="	https://img1.gtimg.com/ninja/2/2021/12/ninja164000518095871.jpg">
          </div>
          <div v-if="scope.row.projectName == '5'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000519727177.jpg">
          </div>
          <div v-if="scope.row.projectName == '6'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000521359465.jpg">
          </div>
          <div v-if="scope.row.projectName == '7'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000524375745.jpg">
          </div>
          <div v-if="scope.row.projectName == '8'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000525397039.jpg">
          </div>
          <div v-if="scope.row.projectName == '9'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000526940758.jpg">
          </div>
          <div v-if="scope.row.projectName == '10'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164005387040545.jpg">
          </div>
          <div v-if="scope.row.projectName == '11'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000539375411.jpg">
          </div>
          <div v-if="scope.row.projectName == '12'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000532450594.jpg">
          </div>
          <div v-if="scope.row.projectName == '13'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000533948069.jpg">
          </div>
          <div v-if="scope.row.projectName == '14'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000536791173.jpg">
          </div>
          <div v-if="scope.row.projectName == '15'">
            <img src="https://img1.gtimg.com/ninja/2/2021/12/ninja164000537839904.jpg">
          </div>

        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" :formatter="formatterProjectName"/>
      <el-table-column label="项目种类" align="center" prop="projectType">
<!--        :0-单人赛，1-双人赛，3-团体赛-->
        <template slot-scope="scope">
          {{scope.row.projectType == 1 ? '单人赛':scope.row.projectType == 2 ? '双人赛': scope.row.projectType == 3 ?'团体赛':'--' }}
        </template>
      </el-table-column>
      <el-table-column label="比赛地点" align="center" prop="competitionSite"  :formatter="formatterSite">
      </el-table-column>
      <el-table-column label="赛事开始时间" align="center" prop="actionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actionTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="已报名人数" align="center" prop="applicationNumber" />-->
      <el-table-column label="备注" align="center" prop="extField" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:information:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:information:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            @click="view(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="项目名称" prop="projectName">
<!--          <el-input v-model="form.projectName" placeholder="请输入项目名称" />-->
          <el-select v-model="form.projectName" placeholder="请选择"  @change="selectExitSelectConfig" clearable>
            <el-option
              v-for="item in opations1"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目种类" prop="projectType">
<!--          :0-单人赛，1-双人赛，3-团体赛-->
          <el-select v-model="form.projectType" placeholder="请选择项目种类"   clearable>
            <el-option
              v-for="dict in projectTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="比赛地点" prop="competitionSite">
<!--          <el-input v-model="form.competitionSite" placeholder="请输入比赛地点" />-->
          <el-select v-model="form.competitionSite" placeholder="请选择比赛地点" clearable>
            <el-option
              v-for="dict in competitionSiteList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="赛事开始时间" prop="actionTime">
          <el-date-picker
            clearable
            v-model="form.actionTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            align="right"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="赛事结束时间" prop="eventEndTime">-->
<!--          <el-date-picker-->
<!--            clearable-->
<!--            v-model="form.eventEndTime"-->
<!--            type="datetime"-->
<!--            placeholder="选择日期时间"-->
<!--            value-format="yyyy-MM-dd HH:mm:ss"-->
<!--            align="right"-->
<!--            :picker-options="pickerOptions1">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="已报名人数" prop="applicationNumber">-->
<!--          <el-input style="width: 220px" v-model="form.applicationNumber" placeholder="请输入已报名人数" />-->
<!--        </el-form-item>-->
        <el-form-item label="备注" prop="extField">
          <el-input type="textarea" :rows="4" maxlength="200" show-word-limit v-model="form.extField" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInformation, getInformation, delInformation, addInformation, updateInformation } from "@/api/system/information";

export default {
  name: "Information",
  dicts: ['sys_oper_type'],
  data() {
    return {
      /**
       * 时间选择器
       */
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      pickerOptions1: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      opations:[
        {
          value: '1',
          label: '短道速滑'
        }, {
          value: '2',
          label: '速度滑冰'
        }, {
          value: '3',
          label: '花样滑冰'
        }, {
          value: '4',
          label: '冰球'
        }, {
          value: '5',
          label: '冰壶'
        }, {
          value: '6',
          label: '雪车'
        }, {
          value: '7',
          label: '钢架雪车'
        }, {
          value: '8',
          label: '雪橇'
        }, {
          value: '9',
          label: '冬季两项'
        }, {
          value: '10',
          label: '高山滑雪'
        }, {
          value: '11',
          label: '自由式滑雪'
        }, {
          value: '12',
          label: '单板滑雪'
        }, {
          value: '13',
          label: '越野滑雪'
        }, {
          value: '14',
          label: '跳台滑雪'
        },{
          value: '15',
          label: '北欧两项'
        }
      ],
      opations1:[
        {
          value: '1',
          label: '短道速滑'
        }, {
          value: '2',
          label: '速度滑冰'
        }, {
          value: '3',
          label: '花样滑冰'
        }, {
          value: '4',
          label: '冰球'
        }, {
          value: '5',
          label: '冰壶'
        }, {
          value: '6',
          label: '雪车'
        }, {
          value: '7',
          label: '钢架雪车'
        }, {
          value: '8',
          label: '雪橇'
        }, {
          value: '9',
          label: '冬季两项'
        }, {
          value: '10',
          label: '高山滑雪'
        }, {
          value: '11',
          label: '自由式滑雪'
        }, {
          value: '12',
          label: '单板滑雪'
        }, {
          value: '13',
          label: '越野滑雪'
        }, {
          value: '14',
          label: '跳台滑雪'
        },{
          value: '15',
          label: '北欧两项'
        }
      ],
      //弹窗
      //项目种类
      projectTypeList:[
        {
          value: 1,
          label: '单人赛'
        },
        {
          value: 2,
          label: '双人赛'
        },
        {
          value: 3,
          label: '团体赛'
        }
      ],
      //比赛场地
      competitionSiteList:[
        {
          value: '1',
          label: '首都体育馆'
        },
        {
          value: '2',
          label: '国家速滑馆'
        },
        {
          value: '3',
          label: '国家体育馆'
        },
        {
          value: '4',
          label: '五棵松体育中心'
        },
        {
          value: '5',
          label: '国家游泳中心'
        },
        {
          value: '6',
          label: '首钢滑雪大跳台中心'
        },
        {
          value: '7',
          label: '国家雪车雪橇中心'
        },
        {
          value: '8',
          label: '国家高山滑雪中心'
        },
        {
          value: '9',
          label: '云顶滑雪公园'
        },
        {
          value: '10',
          label: '国家跳台滑雪中心'
        },
        {
          value: '11',
          label: '国家越野滑雪中心'
        },
        {
          value: '12',
          label: '国家冬季两项中心'
        }
      ],
      //查询条件
      projectTypeList1:[
        {
          value: 1,
          label: '单人赛'
        },
        {
          value: 2,
          label: '双人赛'
        },
        {
          value: 3,
          label: '团体赛'
        }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目信息表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectType: null,
        actionTime: [],
        endTime:null,
        startTime:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        projectType: [
          { required: true, message: "项目种类不能为空", trigger: "change" }
        ],
        competitionSite: [
          { required: true, message: "比赛地点不能为空", trigger: "blur" }
        ],
        actionTime: [
          { required: true, message: "赛事开始时间不能为空", trigger: "blur" }
        ],
        applicationNumber: [
          { required: true, message: "已报名人数不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    selectExitSelectConfig(val){
      if(this.form.projectName == ''){
        this.form.competitionSite = ''
      }
      switch (this.form.projectName) {
        case '1':
        case '3' :
          return  this.form.competitionSite = '1';
          break;
        case '2' :
          return  this.form.competitionSite = '2';
          break;
        case '4' :
          return  this.form.competitionSite = '4';
          break;
        case '5' :
          return  this.form.competitionSite = '5';
          break;
        case '6' :
        case '7' :
        case '8' :
          return  this.form.competitionSite = '7';
          break;
        case '9' :
          return  this.form.competitionSite = '12';
          break;
        case '10' :
          return  this.form.competitionSite = '8';
          break;
        case '11' :
          return  this.form.competitionSite = '6';
          break;
        case '12' :
          return  this.form.competitionSite = '9';
          break;
        case '13' :
          return  this.form.competitionSite = '10';
          break;
        case '14' :
          return  this.form.competitionSite = '11';
          break;
        case '15' :
          return  this.form.competitionSite = '10';
          break;
      }

    },
    /**
     * 比赛地点
     */
    formatterSite(row,cloumn){
      switch (row.competitionSite) {
        case '1':
          return '首都体育馆';
          break;
        case '2':
          return '国家速滑馆';
          break;
        case '3':
          return '国家体育馆';
          break;
        case '4':
          return '五棵松体育中心';
          break;
        case '5':
          return '国家游泳中心';
          break;
        case '6':
          return '首钢滑雪大跳台中心';
          break;
        case '7':
          return '国家雪车雪橇中心';
          break;
        case '8':
          return '国家高山滑雪中心';
          break;
        case '9':
          return '云顶滑雪公园';
          break;
        case '10':
          return '国家跳台滑雪中心';
          break;
        case '11':
          return '国家越野滑雪中心';
          break;
        case '12':
          return '国家冬季两项中心';
          break;
        default:
          return '未知';
      }
    },
    formatterProjectImage(row, column){
      switch(row.projectName){
        case '1':
          return 'https://img1.gtimg.com/ninja/2/2021/12/ninja164000516743104.jpg';
          break;
        case '2':
          return 'https://img1.gtimg.com/ninja/2/2021/12/ninja164000516743104.jpg';
          break;
        case '3':
          return '花样滑冰';
          break;
        case '4':
          return '冰球';
          break;
        case '5':
          return '冰壶';
          break;
        case '6':
          return '雪车';
          break;
        case '7':
          return '钢架雪车';
          break;
        case '8':
          return '雪橇';
          break;
        case '9':
          return '冬季两项';
          break;
        case '10':
          return '高山滑雪';
          break;
        case '11':
          return '自由式滑雪';
          break;
        case '12':
          return '单板滑雪';
          break;
        case '13':
          return '跳台滑雪';
          break;
        case '14':
          return '越野滑雪';
          break;
        case '15':
          return '北欧两项';
          break;
        default:
          return '未知';
      }
    },
    /**
     * 项目名称
     */
    formatterProjectName(row, column){
      switch(row.projectName){
        case '1':
          return '短道速滑';
          break;
        case '2':
          return '速度滑冰';
          break;
        case '3':
          return '花样滑冰';
          break;
        case '4':
          return '冰球';
          break;
        case '5':
          return '冰壶';
          break;
        case '6':
          return '雪车';
          break;
        case '7':
          return '钢架雪车';
          break;
        case '8':
          return '雪橇';
          break;
        case '9':
          return '冬季两项';
          break;
        case '10':
          return '高山滑雪';
          break;
        case '11':
          return '自由式滑雪';
          break;
        case '12':
          return '单板滑雪';
          break;
        case '13':
          return '跳台滑雪';
          break;
        case '14':
          return '越野滑雪';
          break;
        case '15':
          return '北欧两项';
          break;
        default:
          return '未知';
      }
    },
    /** 查询项目信息列表 */
    getList() {
      this.loading = true;
      const self = this
      if(self.queryParams.actionTime){
        self.queryParams.startTime =self.queryParams.actionTime[0]
        self.queryParams.endTime =self.queryParams.actionTime[1]
      }else{
        delete  self.queryParams.startTime
        delete  self.queryParams.endTime
      }
      const queryObj = Object.assign({}, self.queryParams)
      delete queryObj.actionTime
      listInformation(queryObj).then(response => {
        self.informationList = response.rows;
        self.total = response.total;
        self.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        projectType: null,
        competitionSite: null,
        actionTime: null,
        applicationNumber: null,
        extField: null,
        extField1: null,
        extField2: null,
        isDeleted: null,
        createUserid: null,
        createUsername: null,
        createTime: null,
        serverIp: null,
        updateUserid: null,
        updateUsername: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInformation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    view(row){
      this.$router.push({
        name:'detail',
        query:{
          projectType:row.projectType,
          projectName:row.projectName
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目信息编号为"' + ids + '"的数据项？').then(function() {
        return delInformation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/information/export', {
        ...this.queryParams
      }, `information_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
